<%--
    Document   : LibraryBook
    Created on : 14.02.2010, 12:34:31
    Author     : Morfant
--%>


<%@page import="stud.cp.user.valueobjects.PropertyListValue"%>
<%@page import="stud.cp.user.valueobjects.Weapon"%>
<%@page import="java.util.Map"%>
<%@page import="stud.cp.user.valueobjects.WeaponType"%>
<%@page import="java.util.List"%>
<%@page import="stud.cp.user.valueobjects.Property"%>
<%@page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" language="java"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <%@include file="/header.jsp" %>
    <body>
        <div class="page">
            <%@include file="/cap.jsp" %>
            <div id="main">
                <%WeaponType weaponType = (WeaponType) request.getAttribute(PluginConst.WEAPON_TYPE);%>
                <h2>Новое оружие.  Тип - <%=weaponType.getName()%>.</h2>
                <form action="<%= response.encodeURL("weapon-action.do")
                                        + "?"
                                        + PluginConst.SUBACTION
                                        + "="
                                        + PluginConst.NEW_DATA
                                        + "&"
                                        + PluginConst.WEAPON_TYPE_ID
                                        + "="
                                        + weaponType.getWeapon_type_id()%>" 
                      method="post"
                      name="<%= PluginConst.FORM_NAME%>">
                    <fieldset>
                        <legend>Данные</legend>
                        <%String temp = (String) request.getAttribute(PluginConst.ERROR_MESSAGE);
                                    if (temp != null) {%>
                        <p>
                            <span class="error">
                                <%=temp%>
                            </span>
                        </p>
                        <%}%>
                        <p>
                            <span class="highlight-delete-item">
                                <label for="<%=PluginConst.WEAPON_NAME%>">
                                    Название оружия:
                                </label>
                            </span>
                            <input type="text"
                                   name="<%=PluginConst.WEAPON_NAME%>"
                                   value="" />
                            <span class="error"> *</span>
                        </p>

                        <p>
                            <span class="highlight-delete-item">
                                <label for="<%=PluginConst.WEAPON_DESCRIPTION%>">
                                    Описание оружия:
                                </label>
                            </span>
                            <textarea rows="7"
                                      cols="40"
                                      name="<%=PluginConst.WEAPON_DESCRIPTION%>"></textarea>
                            <span class="error"> *</span>
                        </p>

                        <%List<Property> list = (List<Property>) request.getAttribute(PluginConst.PROPERTIES_LIST);
                                    Map<Integer, List> mapOfValueResorses =
                                            (Map<Integer, List>) request.getAttribute(PluginConst.PROPERTY_VALUE_RESORSES);
                                    if ((list != null) && (list.size() > 0)) {
                                        String lastGroupName = "";
                                        String propertyType = "";
                                        for (Property item : list) {
                                            propertyType = item.getProperty_type_id().toString();
                                            if (!item.getPropertyGroupName().equals(lastGroupName)) {
                                                if (!lastGroupName.equals("")) {%>
                    </fieldset>
                    <%}%>
                    <fieldset>
                        <legend><%=item.getPropertyGroupName()%></legend>
                        <%lastGroupName = item.getPropertyGroupName();
                                                                    }%>
                        <p>
                            <span class="highlight-delete-item">
                                <label for="<%=item.getProperty_id()%>"><%=item.getName()%>:</label>
                            </span>

                            <% if (propertyType.equals(PluginConst.TEXT_TYPE)) {%>
                            <input type="text" name="<%=item.getProperty_id()%>" value="" />
                            <%}%>
                            <% if (propertyType.equals(PluginConst.REFERENCE_TYPE)) {%>
                            <select  name="<%=item.getProperty_id()%>">
                                <option value="0">
                                    -
                                </option>
                                <%List referenceValues = mapOfValueResorses.get(item.getProperty_id());
                                     Weapon weapon = null;
                                     for (Object value : referenceValues) {
                                         weapon = (Weapon) value;
                                %>
                                <option value="<%=weapon.getWeapon_id()%>">
                                    <%=weapon.getName()%>
                                </option>
                                <%}%>
                            </select>
                            <%}%>


                            <% if (propertyType.equals(PluginConst.LIST_TYPE)) {%>
                            <select  name="<%=item.getProperty_id()%>">
                                <%List referenceValues = mapOfValueResorses.get(item.getProperty_id());
                                     PropertyListValue propertyListValue = null;
                                     for (Object value : referenceValues) {
                                         propertyListValue = (PropertyListValue) value;
                                %>
                                <option value="<%=propertyListValue.getProperty_list_value_id()%>">
                                    <%=propertyListValue.getValue()%>
                                </option>
                                <%}%>
                            </select>
                            <%}%>

                        <p/>
                        <%}%>
                    </fieldset>
                    <%}%>
                    <p>
                        <span class="error"> *</span> - обязательные для заполнения поля.
                    </p>
                    </fieldset>
                    <p>
                        <input name="confirmButton" type="submit" value="Добавить" />
                    </p>
                </form>
                <script  type="text/javascript">
                    var frmvalidator = new Validator("<%=PluginConst.FORM_NAME%>");
                                        frmvalidator.EnableMsgsTogether();
                    frmvalidator.
                        addValidation("<%=PluginConst.WEAPON_NAME%>",
                                        "req","Имя оружия не может быть пустым!");
                    frmvalidator.
                        addValidation("<%=PluginConst.WEAPON_NAME%>",
                                        "maxlen=70","Слишком длинное имя!");
                    frmvalidator.
                        addValidation("<%=PluginConst.WEAPON_DESCRIPTION%>",
                                        "req","Описание типа оружия не может быть пустым!");
                    frmvalidator.
                        addValidation("<%=PluginConst.WEAPON_DESCRIPTION%>",
                    "maxlen=900","Слишком много символов!");
                </script>
                <div id="weaponmenucontainer">
                    <ul id="weaponmenu">
                        <li><a href="<%= response.encodeURL("weapon-action.do")
                                                + "?"
                                                + PluginConst.SUBACTION
                                                + "="
                                                + PluginConst.GET_LIST
                                                + "&"
                                                + PluginConst.WEAPON_TYPE_ID
                                                + "="
                                                + weaponType.getWeapon_type_id()%>">Вернуться к списку оружия</a></li>
                    </ul>
                </div>
            </div>
        </div>
    </body>
</html>
